package com.markus.code.二叉树.leetcode;

/**
 * Author:markusZhang
 * Date:Create in 2020/8/12 22:27
 * todo: 二叉树的深度
 */
public class LeetCode_104 {
    public static class TreeNode{
        int val;
        TreeNode left;
        TreeNode right;
        public TreeNode(int val){
            this.val = val;
        }
    }
    public static class Info{
        public Integer maxDepth;
        public Info(int maxDepth){
            this.maxDepth = maxDepth;
        }
    }
    public int maxDepth(TreeNode root) {
        if (root == null){
            return 0;
        }
        return process(root).maxDepth;
    }
    private Info process(TreeNode x){
        if (x == null){
            return new Info(0);
        }
        Info left = process(x.left);
        Info right = process(x.right);
        Integer maxDepth = Math.max(left.maxDepth,right.maxDepth)+1;
        return new Info(maxDepth);
    }
}
